In this set of exercises, we clone and work on the GitHub repository you have created in the previous session.

In order to do the following exercises, you should have gone through the steps described in the setup information for the workshop. Specifically, you should…

Exercise 1

After we’ve made sure that everything works, we can now clone and work on the repository we have created on GitHub in the previous session. When doing this, you should also create a new RStudio project.
You can create a new version-controlled project that is connected to an existing GitHub repository via the RStudio menu. If you need some further information, you can check out the New project, GitHub first section in Happy Git and GitHub for the useR.
You can create a new version-controlled project and associate it with a repository cloned from GitHub via File -> New Project -> Version Control. Then choose Git, enter the URL of the GitHub repository, and choose a location where to store the project on your local machine. As we will start working on the project right away, also check “Open in new session”.

Exercise 2

If everything has worked, a new instance of RStudio should have opened with the working directory set to the location of your new project, the files included in the project folder visible in the Files tab, and an active Git tab. To make extra sure that everything worked, let’s check the Git status of our project via the Terminal in RStudio.
You may want to check which shell the Terminal in RStudio uses via Tools -> Global Options -> Terminal. If you use Windows, you should choose Git Bash (which you should have installed with Git for Windows).
git status

Exercise 3

Now that the project is set up and in sync with the remote repository, we can start working on it. Modify the README file (just add, remove or edit a few words). If you have not already done so, add (stage & commit) the R Markdown report (and its resulting output) you generated yesterday to your repository/project.

After modifying the file(s), save the changes (via the Save icon in the RStudio menu or the keyboard shortcut your OS uses for saving files) and stage them in Git.
You can use the RStudio GUI for staging changes (for modified or added files). As a reminder: When you modify existing files and/or create new ones and save the changes, these should be displayed in the Git tab in RStudio and their status will be indicated as modified (M) or untracked (??).
You can stage changed files in the RStudio GUI by checking the boxes in the Staged column in the Git tab.

Exercise 4

After staging your changes, let’s create a commit and push that to the remote repository.
You can do both (committing and pushing) via the RStudio GUI. Remember to write a meaningful commit message.
After staging the changes, simply click on the Commit button in the Git tab in RStudio, write a commit message in the menu that opens up, and then click the Push button in the same menu.

Exercise 5

As a final exercise for this session, let’s do the opposite of pushing and pull changes from the remote repository to your local project. Before we can do this, we first need to make some edits in the remote repository. Go to the website of your remote GitHub repository (while being logged in) and edit the README file in the browser (again, just add, remove, or edit a few words). Once you have edited the file (and committed the changes directly on GitHub), pull the changes to your local project.

You can edit the README via the small pen icon next displayed above the content of your README file on the website of your GitHub repository.

Remember that if you edit a file directly via the GitHub web interface, you also need to make a commit (and add a commit message).
After making and committing the edits to the README file via the GitHub web interface, you can simply click the Pull button in the Git tab in RStudio to update your local project.